<?php

class TreeSearchBeahvior extends CActiveRecordBehavior {
	
	public $treeParentId;
	public $modelName = '';
	public $attribute;
	public $treeKeyName = 'id';
	
	public function beforeFind(CModelEvent $event) {
		
		$criteria = $this->getOwner()->getDbCriteria();
		$treeParentId = $this->treeParentId;
		if (empty($treeParentId)) return true;
		$treeModel = new $this->modelName;
		
		$model = $treeModel->findByPk($treeParentId);
		if (is_object($model)) {
			$models = $model->getDesWithSelf();
			$criteria->addInCondition(
				$this->attribute, CHtml::listData(
					$models, $this->treeKeyName, $this->treeKeyName
				)
			);
		}
		
	}
	

}

?>